﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

// Token: 0x020003B4 RID: 948
public class MoveableUI : MonoBehaviour
{
	// Token: 0x1700024F RID: 591
	// (get) Token: 0x060017A2 RID: 6050 RVA: 0x0009C538 File Offset: 0x0009A738
	// (set) Token: 0x060017A3 RID: 6051 RVA: 0x0009C540 File Offset: 0x0009A740
	public MoveableUI.STATE State { get; protected set; }

	// Token: 0x060017A4 RID: 6052 RVA: 0x0009C54C File Offset: 0x0009A74C
	private void Awake()
	{
		EventTrigger.Entry entry = new EventTrigger.Entry();
		entry.eventID = EventTriggerType.PointerDown;
		entry.callback.AddListener(delegate(BaseEventData data)
		{
			this.OnActiveSort();
		});
		this.GetEventTrigger().triggers.Add(entry);
	}

	// Token: 0x060017A5 RID: 6053 RVA: 0x0009C590 File Offset: 0x0009A790
	private void Start()
	{
		this.gameCtrl = UnityEngine.Object.FindObjectOfType<GameControl>();
	}

	// Token: 0x060017A6 RID: 6054 RVA: 0x0009C5A0 File Offset: 0x0009A7A0
	private void OnActiveSort()
	{
		base.transform.SetAsLastSibling();
	}

	// Token: 0x060017A7 RID: 6055 RVA: 0x0009C5B0 File Offset: 0x0009A7B0
	public void SetTitle(string str)
	{
		this.title.text = str;
	}

	// Token: 0x060017A8 RID: 6056 RVA: 0x0009C5C0 File Offset: 0x0009A7C0
	public void AddOnChange(UnityAction<MoveableUI.STATE> act)
	{
		this.onChangeState.AddListener(act);
	}

	// Token: 0x060017A9 RID: 6057 RVA: 0x0009C5D0 File Offset: 0x0009A7D0
	public void RemoveAllListenersOnChange()
	{
		this.onChangeState.RemoveAllListeners();
	}

	// Token: 0x060017AA RID: 6058 RVA: 0x0009C5E0 File Offset: 0x0009A7E0
	private void ChangeState(MoveableUI.STATE next)
	{
		this.State = next;
		if (this.State == MoveableUI.STATE.OPEN)
		{
			base.gameObject.SetActive(true);
			this.hideableArea.gameObject.SetActive(true);
			this.OnActiveSort();
		}
		else if (this.State == MoveableUI.STATE.MINIMIZED)
		{
			base.gameObject.SetActive(true);
			this.hideableArea.gameObject.SetActive(false);
		}
		else if (this.State == MoveableUI.STATE.CLOSED)
		{
			base.gameObject.SetActive(false);
		}
		this.minimizeButton.gameObject.SetActive(this.State != MoveableUI.STATE.MINIMIZED);
		this.openButton.gameObject.SetActive(this.State != MoveableUI.STATE.OPEN);
		this.onChangeState.Invoke(this.State);
	}

	// Token: 0x060017AB RID: 6059 RVA: 0x0009C6B8 File Offset: 0x0009A8B8
	public void Open()
	{
		this.ChangeState(MoveableUI.STATE.OPEN);
		if (base.gameObject.activeInHierarchy)
		{
			SystemSE.Play(SystemSE.SE.OPEN);
		}
	}

	// Token: 0x060017AC RID: 6060 RVA: 0x0009C6D8 File Offset: 0x0009A8D8
	public void Minimize()
	{
		if (base.gameObject.activeInHierarchy)
		{
			SystemSE.Play(SystemSE.SE.CLOSE);
		}
		this.ChangeState(MoveableUI.STATE.MINIMIZED);
	}

	// Token: 0x060017AD RID: 6061 RVA: 0x0009C6F8 File Offset: 0x0009A8F8
	public void Close()
	{
		if (base.gameObject.activeInHierarchy && this.State != MoveableUI.STATE.CLOSED)
		{
			SystemSE.Play(SystemSE.SE.CLOSE);
		}
		this.ChangeState(MoveableUI.STATE.CLOSED);
	}

	// Token: 0x060017AE RID: 6062 RVA: 0x0009C724 File Offset: 0x0009A924
	public EventTrigger GetEventTrigger()
	{
		EventTrigger component = base.GetComponent<EventTrigger>();
		if (component)
		{
			return component;
		}
		return base.gameObject.AddComponent<EventTrigger>();
	}

	// Token: 0x04001B32 RID: 6962
	[SerializeField]
	private Text title;

	// Token: 0x04001B33 RID: 6963
	[SerializeField]
	private RectTransform hideableArea;

	// Token: 0x04001B34 RID: 6964
	[SerializeField]
	private Button minimizeButton;

	// Token: 0x04001B35 RID: 6965
	[SerializeField]
	private Button openButton;

	// Token: 0x04001B36 RID: 6966
	[SerializeField]
	private Button closeButton;

	// Token: 0x04001B38 RID: 6968
	public MoveableUI.ChangeStateEvent onChangeState;

	// Token: 0x04001B39 RID: 6969
	private GameControl gameCtrl;

	// Token: 0x020003B5 RID: 949
	public enum STATE
	{
		// Token: 0x04001B3B RID: 6971
		CLOSED,
		// Token: 0x04001B3C RID: 6972
		MINIMIZED,
		// Token: 0x04001B3D RID: 6973
		OPEN
	}

	// Token: 0x020003B6 RID: 950
	[Serializable]
	public class ChangeStateEvent : UnityEvent<MoveableUI.STATE>
	{
	}
}
